
layui.use('carousel', function(){
  let carousel = layui.carousel;

  // 加载轮播图数据
  function loadSwiper(){
    $.ajax({
      type: 'get',
      url: 'http://localhost:8888/api/swipers',
      success: function (res) {
        console.log(res)
        if (res.status === 0) {
          let str = '';
          res.data.forEach(item =>{
            str +=  `
              <li class="img-effect">
                <a href="javascript:;">
                  <img src="http://localhost:8888/uploads/${item.swiperimg}" alt="">
                </a>
              </li>`
          })
          $('#lunbotu').html(str);
          // 轮播交互作用
          carousel.render({
            elem: '#kr_carousel',
            width: 720,
            height: 300,
            interval: 3000
          })
        }
      }
    })
  }

  loadSwiper()

// 加载友情链接数据

function loadLink() {
  $.ajax({
    type: 'get',
    url: 'http://localhost:8888/api/links',
    success: function (res) {
      if (res.status === 0) {
        let arr = ['<dt>合作伙伴</dt>']
        res.data.forEach(function (item) {
          arr.push(`
            <dd>
              <a href="javascript:;">
                <img src="${'http://localhost:8888/uploads/' + item.linkicon}" alt="${item.linkname}">
              </a>
            </dd>
          `)
        })
        $('.kr_collaborator').html(arr.join(''))
      }
    }
  })
}
loadLink()

})
